package com.hiwan.system.common.web;
import java.util.List;

import javax.servlet.ServletConfig;

import org.framework.service.SysInit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.hiwan.platform.util.StackTraceUtil;
/**
 * 
 * 系统框架初始化数据
 * 
 * @author WQ
 */
@Component
@Transactional
public class HiwanFrameworkSysManager {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    private List<SysInit> sysInitList;
    private SysInit dictInit;
    private SysInit propertiesInit;
    private String sysRubbishClearDisabled;
    /**
     * 系统初始化
     */
    public void hiwanFrameworkSysInit(ServletConfig config) {
        logger.info("---Hiwanframework系统初始化开始---");
        // 用于进行servlet初始化数据的传递
        try {
            logger.info("---系统字典表初始化开始---");
            if (dictInit != null) {
                dictInit.sysInit();
            }
            logger.info("---系统字典表初始化结束---");
            logger.info("---系统配置文件信息初始化开始---");
            if (propertiesInit != null) {
                propertiesInit.sysInit();
            }
            logger.info("---系统配置文件信息初始化结束---");
            // 判断是否需要启动垃圾清理机制
            if ("true".equals(sysRubbishClearDisabled)) {
                logger.info("---系统垃圾清理机制启动开始---");
                HiwanFrameworkSysClearThread hwSysClearThread = new HiwanFrameworkSysClearThread();
                hwSysClearThread.start();
                logger.info("---系统垃圾清理机制启动成功---");
            }
            if (sysInitList != null) {
                for (SysInit sys : sysInitList) {
                    sys.sysInit();
                }
            }
            logger.info("---Hiwanframework系统初始化结束---");
        } catch (Exception ex) {
            logger.error("---Hiwanframework系统初始化失败:\n{}",
                    StackTraceUtil.getStackTrace(ex));
        }
        logger.info("---Hiwanframework系统启动成功---");
    }
    public List<SysInit> getSysInitList() {
        return sysInitList;
    }
    public void setSysInitList(List<SysInit> sysInitList) {
        this.sysInitList = sysInitList;
    }
    public SysInit getDictInit() {
        return dictInit;
    }
    public void setDictInit(SysInit dictInit) {
        this.dictInit = dictInit;
    }
    public SysInit getPropertiesInit() {
        return propertiesInit;
    }
    public void setPropertiesInit(SysInit propertiesInit) {
        this.propertiesInit = propertiesInit;
    }
    public String getSysRubbishClearDisabled() {
        return sysRubbishClearDisabled;
    }
    public void setSysRubbishClearDisabled(String sysRubbishClearDisabled) {
        this.sysRubbishClearDisabled = sysRubbishClearDisabled;
    }
}